package com.example.administrator.yunniuusedcar.holder;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.common.base.MyApp;
import com.example.administrator.yunniuusedcar.MainActivity;
import com.example.administrator.yunniuusedcar.activity.ActionPromotionActivity;
import com.example.administrator.yunniuusedcar.activity.BuyingCarGuideActivity;
import com.example.administrator.yunniuusedcar.activity.DetailsCarActivity;
import com.example.administrator.yunniuusedcar.activity.HJingPingCarActivity;
import com.example.administrator.yunniuusedcar.activity.HaoCarJifenShopActivity;
import com.example.administrator.yunniuusedcar.activity.LinePhysicalStoreActivity;
import com.example.administrator.yunniuusedcar.activity.SeconHandCarActivity;
import com.example.administrator.common.base.Global;
import com.example.administrator.common.ui.BaseAdapterRV;
import com.example.administrator.common.ui.BaseHolderRV;
import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.model.mode_benn.HomeMenuBean;
import com.example.administrator.yunniuusedcar.ui.ShopDetailActivity;
import com.squareup.picasso.Picasso;

import java.io.Serializable;

/** 首页头部类别    菜单栏
 * Created by USER2015 on 2017/12/3.
 */

public class HomeCategoryHolder extends BaseHolderRV<HomeMenuBean.Data> {

    private LinearLayout lll;

    public HomeCategoryHolder(Context context, ViewGroup parent,
                              BaseAdapterRV<HomeMenuBean.Data> adapter) {
        super(context, parent, adapter, R.layout.item_grid);   // 内容
    }

    private ImageView ivIcon;
    private TextView tvTitle;

    // 查找子控件
    @Override
    public void onFindViews(View itemView) {
        ivIcon = (ImageView) itemView.findViewById(R.id.iv_icon2);
        tvTitle = (TextView) itemView.findViewById(R.id.tv_title2);
//        lll = (LinearLayout) itemView.findViewById(R.id.lll);
//        lll.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//              if( (int) lll.getTag()==0){
//                  Global.showToast("iadfsjid"+lll.getTag());
//
//              };
//            }
//        });

        // 设置itemView的宽度
        int width = (int) (Global.mScreenWidth / 4);
        ViewGroup.LayoutParams param = itemView.getLayoutParams();  //网格布局
        param.width = width;


        itemView.setLayoutParams(param);
    }

    // 刷新子控件显示
    @Override
    protected void onRefreshView(HomeMenuBean.Data bean, int position) {
//        tvTitle.setText(bean.data.get(position).name);
        tvTitle.setText(bean.name);
//        lll.setTag(position);

        Picasso.with(context).load(bean.logo).into(ivIcon);

    }

    @Override
    protected void onItemClick(View itemView, int position, HomeMenuBean.Data bean) {
        super.onItemClick(itemView, position, bean);

        if (position == 0) {
//                         DetailsCarActivity    CommodityDetailsActivity
            MyApp.enter_type = "typeCar";
            Intent intent = new Intent(MainActivity.mactivity, DetailsCarActivity.class) ;  // 中规豪车
            MainActivity.mactivity. startActivity(intent);
        }
        else if (position == 1 ){
            Intent intent = new Intent(MainActivity.mactivity, HaoCarJifenShopActivity.class);  // 豪车积分
            MainActivity.mactivity. startActivity(intent);
        }
        else if (position == 2 ){
            Intent intent = new Intent(MainActivity.mactivity, ShopDetailActivity.class);  // 平行进口  （不稳定，存有bug）
            MainActivity.mactivity. startActivity(intent);
        }
        else if (position == 3 ){
            Intent intent = new Intent(MainActivity.mactivity, HJingPingCarActivity.class);  //  豪车精品  （只有两item，makebe异常）
            MainActivity.mactivity. startActivity(intent);
        }
//        else if (position == 4 ){
//            Intent intent = new Intent(MainActivity.mactivity, SeconHandCarActivity.class);  //二手豪车   （后台还没有接口）
//            MainActivity.mactivity. startActivity(intent);
//        }
        else if (position == 5 ){
            Intent intent = new Intent(MainActivity.mactivity, BuyingCarGuideActivity.class);  //购车指南
            MainActivity.mactivity. startActivity(intent);
        }
        else if (position == 6 ){
            Intent intent = new Intent(MainActivity.mactivity, ActionPromotionActivity.class);  //活动促销
            MainActivity.mactivity. startActivity(intent);
        }
        else if (position == 7 ){
            Intent intent = new Intent(MainActivity.mactivity, LinePhysicalStoreActivity.class);  //线下实体店
            MainActivity.mactivity. startActivity(intent);
        }

    }
}

